package extend.client.base;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

/**
 * header 信息
 * <B>说明：</B>
 * <pre>
 *  略
 * </pre>
 * <B>示例：</B>
 * <pre>
 *  略
 * </pre>
 * <B>日志：</B>
 * <pre>
 *  略
 * </pre>
 * <B>注意事项：</B>
 * <pre>
 *  略
 * </pre>
 */
public class Header
{
    private Map<String,String> headers;

    public Header()
    {
        this.headers = new HashMap<>();
    }

    public Header(Map<String,String> headers)
    {
        this.headers = headers;
    }

    public void set(String key, String value)
    {
        this.headers.put(key,value);
    }

    public String get(String key)
    {
        return this.headers.get(key);
    }

    public void add(String key, String value)
    {
        if (this.has(key)) {
            this.set(key,this.get(key) + value);
        } else {
            this.set(key,value);
        }
    }

    public void remove(String key)
    {
        this.headers.remove(key);
    }

    public void putAll(Map<String,String> headers)
    {
        if (this.headers != null) {
            this.headers.putAll(headers);
        }
    }

    public boolean has(String key)
    {
        if (this.headers.containsKey(key)) {
            return true;
        } else {
            return false;
        }
    }

    /**
     * 获取迭代器
     *<B>说明：</B>
     *<pre>
     *  略
     *</pre>
     */
    public Iterator<Map.Entry<String, String>> getIterator()
    {
        return this.headers.entrySet().iterator();
    }


}
